package com.hq.xmind;

import org.markdown4j.Markdown4jProcessor;
import org.springframework.util.ResourceUtils;

import java.io.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @ClassName Markdown4j
 * @Description TODO
 * @Author huangzl
 * @Date 2018/10/30 14:19
 * @Version 1.0
 **/
public class Markdown4j {

    public static void main(String[] args) throws IOException {
        File file = ResourceUtils.getFile("classpath:file/markdown2.md");
        Long filelength = file.length();
        byte[] filecontent = new byte[filelength.intValue()];
        try {
            FileInputStream in = new FileInputStream(file);
            in.read(filecontent);
            in.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        String encoding = "UTF-8";
//        String html = new Markdown4jProcessor().process(new String(filecontent, encoding));
//        System.out.println(new String(filecontent, encoding));
//        System.out.println("-----------------------------------");

        String xx=new String(filecontent, encoding);

//        xx="<div itemprop=\"knowledge\">\n" +
//                "\n" +
//                "# Python</div>";
        String pattern = "[\\s\\S]*<div[\\s\\S]*itemprop=\"knowledge\">([\\s\\S]*)" +
                "<div[\\s\\S]*itemprop=\"what\">([\\s\\S]*)</div>[\\s\\S]*" +
                "<div[\\s\\S]*itemprop=\"where\">([\\s\\S]*)</div>[\\s\\S]*" +
                "<div[\\s\\S]*itemprop=\"how\">([\\s\\S]*)</div>[\\s\\S]*</div>###"  ;

        // 创建 Pattern 对象
        Pattern r = Pattern.compile(pattern);

        // 现在创建 matcher 对象
        Matcher m = r.matcher(xx);
        while (m.find( )) {
//            System.out.println("Found value: " + m.group(0) );
            System.out.println("Found value1: " + m.group(1) );
            System.out.println("Found value2: " + m.group(2) );
            System.out.println("Found value3: " + m.group(3) );
            System.out.println("Found value4: " + m.group(4) );
            System.out.println("-----------------------------------");
        }



    }
}